#!/usr/bin/env ruby

class ChangePerms

  def initialize(perms,type,file)
    @perms = perms
    @type = type
    @file = file
  end

  def result
    if @perms == 'none'
      shell_script_output = `chmod #{@type}-rwx #{@file}`
      print "Changed permissions.\n"
    elsif @perms == 'read write' || @perms == 'read xcute' || @perms == 'write read' || @perms == 'write xcute' || @perms == 'xcute read' || @perms == 'xcute write' || @perms == 'read' || @perms == 'write' || @perms == 'xcute' ||@perms == 'read write xcute'
      replaceperms = @perms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
      finalperms = replaceperms.delete("\s")
      shell_script_output = `chmod #{@type}-rwx #{@file}`
      shell_script_output = `chmod #{@type}+#{finalperms} #{@file}`
      print "Changed permissions.\n"
    else
      print "No valid file permissions.\n"
    end
  end
end
